/**
 * CellPositionParser.java
 */
package com.pluginsacceptor.plugin.formula.MathsTrigo.support;

import com.pluginsacceptor.utils.CommunicationUtils;

/**
 * Cell parser
 */
public class CellPositionParser {

    /** */
    private final String userInput;

    /** */
    private int row;

    /** */
    private int column;

    /**
     * Constructor
     * @param userInput
     */
    public CellPositionParser(final String userInput) {
        super();
        this.userInput = userInput.toUpperCase();
    }

    public boolean validate() {
        boolean result = true;

        final String[] coordinate = userInput.split("[ ,.;:]");
        if (coordinate == null || coordinate.length < 2) {
            result = false;
        } else {
            this.column = CommunicationUtils.findColumn(coordinate[0]);
            if (column == -1) {
                result = false;
            } else {
                try {
                    row = Integer.parseInt(coordinate[1]) - 1;
                } catch (final Exception e1) {
                    result = false;;
                }
            }
        }
        return result;
    }

    /**
     * @return the userInput
     */
    public String getUserInput() {
        return userInput;
    }

    /**
     * @return the row
     */
    public int getRow() {
        return row;
    }

    /**
     * @return the column
     */
    public int getColumn() {
        return column;
    }



}
